using UnityEngine;
using UFrame;
using UFrame.Guide;

namespace Guide
{
    public abstract class SimpleBaseGuideCtrl : GuideCtrl, IRegistAble, ILateUpdate
    {
        protected GuideStep m_currentStep;
        public GuideStep CurrentStep => m_currentStep;

        public float Interval => 1;

        public bool Runing => m_guideDic?.Count > 0;

        public virtual void OnRegist()
        {
            //SetFaictor(1001, CheckUIOpen);//检查ui是否打开
            //SetFactor(1002, CheckUIClosed);//检查ui是否关闭
            //SetFactor(1003, CheckUIPosYBigger);//检查ui的y坐标是否大于

            //RegistFactor(2001, OnOpenUI);//打开UI操作
            //RegistFactor(2002, OnOpenTeachUI);//打开UI操作
        }

        public virtual void OnUnRegist()
        {
            m_currentStep = null;
        }

        protected override void OnGuideActived(int guideId)
        {
            base.OnGuideActived(guideId);
            var guideStarted = StartGuiding(guideId);
            if (!guideStarted)
            {
                Debug.Log("OnGuideActived:" + guideId);
            }
            else
            {
                Debug.LogError("guide start failed!");
            }
        }

        protected override void OnStartGuide(int guideId, int stepIndex)
        {
            base.OnStartGuide(guideId, stepIndex);
            Debug.Log("OnGuideStart:" + guideId + " step:" + stepIndex);
        }

        protected override void OnStopGuide(int guideId, int stepId)
        {
            base.OnStopGuide(guideId, stepId);
            Debug.Log("OnGuideStop:" + guideId + "-" + stepId);
        }

        protected override void OnGuideFinish(int guideId, string err = null)
        {
            base.OnGuideFinish(guideId, err);
            Debug.Log("OnGuideFinish:" + guideId);
        }

        protected abstract bool OnOpenUI(string[] args);

        protected abstract bool OnOpenTeachUI(string[] args);

        protected abstract bool CheckUIOpen(string[] args);

        protected abstract bool CheckUIClosed(string[] args);

        protected abstract bool CheckUIPosYBigger(string[] args);

        public void OnLateUpdate()
        {
            RefreshGuide();
        }
    }
}